<div class="grid_4">       
    <div class="da-panel">
        <div class="da-panel-header">
            <span class="da-panel-title">
                <img alt="" src="<?php echo $this->themeUrl; ?>/files/theme/images/icons/color/monitor.png">
                Nhân viên
            </span>
        </div>

        <div id="da-ex-tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
            <?php $this->renderPartial('_tabs')?>
            
            <div role="grid" class="dataTables_wrapper" id="da-ex-datatable-numberpaging_wrapper">
            <?php $this->widget('admin.components.widgets.AlertWidget');?>
                <?php $this->widget('zii.widgets.grid.CGridView', array(
                            'id'=>'manager-grid',
                            'dataProvider'=>$model->search(),
                            'filter'=>$model,
                            'template' => "{items}\n{summary}\n{pager}",
                            'summaryCssClass' => 'dataTables_info',
                            'pagerCssClass' => 'dataTables_paginate paging_full_numbers',
                            'itemsCssClass' => 'da-table dataTable',
                            'summaryText' => 'Hiển thị từ {start} đến {end} trong {count} kết quả.',
                            'beforeAjaxUpdate'=>'function(id,options){
                                $("#ajax-loading").fadeIn();    
                            }',
                            'afterAjaxUpdate'=>'function(id,options){
                                $("#ajax-loading").fadeOut();    
                            }',
                            'columns'=>array(
                                array(
                                    'name' => 'status',
                                    'type'      =>  'raw',
                                    'value' => '$data->statusLabel',
                                    'htmlOptions' => array('style' => 'width: 150px;'),
                                    'filter' => Manager::model()->statusData,
                                ),
                                array(
                                    'name' => 'phone',
                                    'type'      =>  'raw',
                                    'value' => '$data->phone',
                                    'htmlOptions' => array('style' => 'width: 200px;'),
                                ),
                                array(
                                    'name' => 'name',
                                    'value' => '$data->name',
                                    'htmlOptions' => array('style' => 'width: 100px;'),
                                    'type' => 'html',
                                ),
                                array(
                                    'name' => 'address',
                                    'value' => '$data->address',
                                    'htmlOptions' => array('style' => 'width: 100px;'),
                                    'type' => 'html',
                                ),
                                array(
                                    'class'=>'CButtonColumn',
                                    'template'=>'{update} {delete}',
                                    'buttons' => array(
                                        'update' => array(
                                            'url'=>'$data->getAdminUrl("update")',
                                            'visible'=>'
                                                
                                                (Yii::app()->controller->manager->id == $data->id) || 
                                                (Yii::app()->controller->manager->isAdmin && $data->isManager) || 
                                                $data->isStaffOnly || $data->isDisable
                                            
                                            '
                                        ),
                                        'delete' => array(
                                            'url'=>'$data->getAdminUrl("delete")',
                                            'visible'=>'
                                                
                                                (Yii::app()->controller->manager->isAdmin && $data->isManagerOnly) || 
                                                $data->isStaffOnly || $data->isDisable
                                                
                                            ',
                                            'click' => "function() {
                                                if(!confirm('Bạn có chắc là muốn xóa không?')) return false;
                                                var th=this;
                                                var afterDelete=function(){};
                                                $.fn.yiiGridView.update('manager-grid', {
                                                    type:'POST',
                                                    url:$(this).attr('href'),
                                                    success:function(data) {
                                                        $.fn.yiiGridView.update('manager-grid');
                                                        afterDelete(th,true,data);
                                                        if(data!=''){
                                                            window.location = data;
                                                        }
                                                        console.log(data);
                                                    },
                                                    error:function(XHR) {
                                                        return afterDelete(th,false,XHR);
                                                    }
                                                });
                                                return false;
                                            }",
                                        ),
                                    ),
                                ),
                            ),
                        )); ?>             
            </div>

        </div>

    </div>
</div>

<?php
    $cs = Yii::app()->clientScript;
    $this->widget('admin.components.widgets.AlertWidget', array(
        'showMessageDiv' => false
    ));
?>